<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title>Sans Titre</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
<script>
    function validate(form)
    {
       var isChecked=false;
       if(form.txtname.value.length <=0)
       {
           alert("Cannt b empty");
           form.txtname.focus();
           return false;
       }
       var chk=document.getElementsByName("game[]");

       for(var i=0; i<chk.length;i++)
       {
           if(chk[i].checked)
           {
               isChecked=true;
               break;
           }
           if(isChecked==false)
           {                    
               alert("Select atleast one hobby");
               return false;
           }
       }
       return true;
    }
   function callemail(str)
    {
             var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
             if(!regex.test(str))
             {
               alert("Invalid email address format");
               return false;
             }
    return true;
    }



</script>

</script>
</head>
<body bgcolor="#FFFFFF">
<!--onsubmit="return validate(this);"-->
<form method="post" enctype="multipart/form-data"  name="myfrm">
    <table border="1"  align="center">
           <tr>
                         <td>Name:</td>
                         <td> <input type="text" name="txtname"></td>
           </tr>
           <tr>
                           <td>E-Mail:</td>
                           <td><input type="text" name="txtmail" onblur="return callemail(this.value);"></td>
           </tr>

            <tr>
                        <td>Sex</td>
                        <td><input type="radio" name=optsex value="Male" checked>Male
                        <input type="radio" name=optsex value="Female">Female</td>
            </tr>
            <tr>
                <td>Upload Photo</td>
                <td>
                     <input type="file" id="updphoto" name="file">
                </td>
            </tr>
            <tr>
                <td>Hobbies</td>
                <td>
                    <input type="checkbox" name="game[]" value="Cricket">Cricket
                    <input type="checkbox" name="game[]" value="FootBall">FootBall
                    <input type="checkbox" name="game[]" value="Rugby">Rugby
                    <input type="checkbox" name="game[]" value="Lawn Tennis">Lawn Tennis
                </td>
            </tr>
             <tr>
                <td colspan=2 align="center"> <input type="submit" name="add" value="Sign up" ></td>
             </tr>
    </table>
</form>
</html>
</body>
<?

       if($_POST["add"])
       {
           include "connect.php";
           $filepath="Not Found";
           if ($_FILES["file"]["error"] > 0)
           {
               echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
           }
           else
           {
             if (file_exists("image/" . $_FILES["file"]["name"]))
             {
               echo $_FILES["file"]["name"] . " already exists. ";
             }
             else
             {
               move_uploaded_file($_FILES["file"]["tmp_name"],
               "image/" . $_FILES["file"]["name"]);
               $filepath="image/" . $_FILES["file"]["name"];

             }
           }
           $ins="insert into member (memail,msex,mphoto,mname) values('".$_POST["txtmail"]."','".$_POST["optsex"]."','".$filepath."','".$_POST["txtname"]."')";
           echo $ins;
           mysql_query($ins);
           $id=mysql_insert_id();

           foreach(@$_POST["game"] as $val)
           {
               $ins1="insert into hobby values(".$id.",'".$val."')";
               mysql_query($ins1);
               unset($ins1);
           }
           header("location:view.php");
       }
?>

</html>
